//
//  LeftViewController.m
//  囧途
//
//  Created by fly on 16/3/3.
//  Copyright © 2016年 fly. All rights reserved.
//

#import "LeftViewController.h"
#import "ControllerManger.h"
#import "MyOrderViewController.h"
#import "LoginViewController.h"
#import "MyMessageViewController.h"
#import "AboutViewController.h"

#import "LeftMenuTableCell.h"

#import <AVUser.h>

static NSString * const kMenuTableCellReuseIdentifier = @"MenuTableCellReuseIdentifier";

@interface LeftViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UIButton *myOrderButton;
@property (strong, nonatomic) IBOutlet UILabel *label;

@property (weak, nonatomic) IBOutlet UIButton *LoginButton;
@property (strong, nonatomic) IBOutlet UIButton *mymessageButton;

@property(nonatomic, strong)AVUser * user;

@property (strong, nonatomic) IBOutlet UIButton *aboutButton;


@property (weak, nonatomic) IBOutlet UITableView *menuTable;

@end

@implementation LeftViewController

-(void)viewWillAppear:(BOOL)animated
{
    _user = [AVUser currentUser];
    
    if (_user != nil) {
        
        _label.text = _user.username;
    }
    
    else{
    
        _label.text = @"点击头像登陆";
    }
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.menuTable.rowHeight = 100;
    self.menuTable.backgroundColor = [UIColor clearColor];
    self.menuTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.menuTable.contentInset = UIEdgeInsetsMake(136, 0, 0, 0);
    self.menuTable.delegate = self;
    self.menuTable.dataSource = self;
    
}

- (IBAction)myOrderButtonPressed:(UIButton *)sender {
    
    MyOrderViewController * order = [[MyOrderViewController alloc]init];
    
    [[ControllerManger sharedManager].drawerVC closeLeftDrawer];
    
    // 主页推送   现在主页的控制器是导航控制器
    order.navigationItem.title = @"我的订单";
    
    [[ControllerManger sharedManager].homeVC.navigationController pushViewController:order animated:YES];
    
}
- (IBAction)LoginButtonPressed:(UIButton *)sender {

    if (_user == nil) {
        [[ControllerManger sharedManager].drawerVC closeLeftDrawer];
        
        LoginViewController * loginView = [[LoginViewController alloc]init];
        
        [[ControllerManger sharedManager].homeVC.navigationController pushViewController:loginView animated:YES];

    }
    
    else {
        
        [[ControllerManger sharedManager].drawerVC closeLeftDrawer];
        
        MyMessageViewController * view = [[MyMessageViewController alloc]init];
        [[ControllerManger sharedManager].homeVC.navigationController pushViewController:view animated:YES];

    }
    
    
}
- (IBAction)mymessageButton:(UIButton *)sender {
    
    [[ControllerManger sharedManager].drawerVC closeLeftDrawer];
    
    MyMessageViewController * view = [[MyMessageViewController alloc]init];
    [[ControllerManger sharedManager].homeVC.navigationController pushViewController:view animated:YES];
    
}
- (IBAction)aboutButtobPressed:(UIButton *)sender {
    
    [[ControllerManger sharedManager].drawerVC closeLeftDrawer];
    
    AboutViewController * view = [[AboutViewController alloc]init];
    
    [[ControllerManger sharedManager].homeVC.navigationController pushViewController:view animated:YES];
    
    
}

#pragma marks - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LeftMenuTableCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"LeftMenuTableCell" owner:self options:nil] lastObject];
    
    cell.imageView.image = [UIImage imageNamed:@"系统头像1"];
    
    switch (indexPath.row) {
        case 0:
            cell.menuLabel.text = @"我的订单";
            break;
        case 1:
            cell.menuLabel.text = @"个人信息";
            break;
        case 2:
            cell.menuLabel.text = @"我的钱包";
            break;
        case 3:
            cell.menuLabel.text = @"设置";
            break;

    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.row) {
        case 0:
            
            break;
        case 1:
            
            break;
        case 2:
            
            break;
        case 3:
            
            break;
            
    }
}

@end
